package com.qc.searchBug.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qc.searchBug.util.MsgUtil;
import com.qc.searchBug.util.RandomUtil;
import com.qc.searchBug.util.SendMsgUtil;

@Controller
@RequestMapping(value="/sendMsgController")
public class SendMsgController {
	@ResponseBody
	@RequestMapping(value="/sendPhoneMsg" )
	public Object sendPhoneMsg(@RequestParam String phone,@RequestParam int typeId,HttpSession session){
		/*
		 * 1. 获得随机数 2. 通过短信类型,拼接短信的模版 3. 发送短信
		 * 
		 * 4. 解析接口返回的数据情况 5. 异步响应用户的请求
		 */
		String random = RandomUtil.findRandomNumber();
		String msg=null;
		
		if(typeId==1){
			msg = MsgUtil.findUpdatePwd(random);
		}else if(typeId==2){
			msg = MsgUtil.findRigedistr(random);
		}
		int i = SendMsgUtil.sendMsg(msg, phone);
		if(i==1){
			return random;
		}
		else{
			return null;
		}
	}
}
